package com.cai.quartz.listener.trigger;

import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.Trigger;
import org.quartz.TriggerListener;
@Slf4j
public class MyTriggerListener implements TriggerListener {
    /**
     * 监听器名称
     */
    @Override
    public String getName() {
        String name=this.getClass().getSimpleName();
        log.info("监听器名称：【{}】",name);
        return name;
    }

    @Override
    public void triggerFired(Trigger trigger, JobExecutionContext jobExecutionContext) {
            String name=trigger.getKey().getName();
            log.info("{} job即将被执行",name);
    }

    @Override
    public boolean vetoJobExecution(Trigger trigger, JobExecutionContext jobExecutionContext) {
        String name = trigger.getKey().getName();
        log.info("{} 没有被触发",name);
        //return true;  不会执行job方法
        return false;

    }

    @Override
    public void triggerMisfired(Trigger trigger) {
        log.info("错过触发");
    }

    @Override
    public void triggerComplete(Trigger trigger, JobExecutionContext jobExecutionContext, Trigger.CompletedExecutionInstruction completedExecutionInstruction) {
        String name = trigger.getKey().getName();
        log.info("{} 完成触发之后，job执行完毕",name);
    }
}
